import json

import pandas as pd

mock_json = "[{ name: 'Snowfall (cm)', type: 'column', yAxis: 1, color: '#38A1C1', data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], tooltip: {  valueSuffix: ' cm' }}, { name: 'Average Snowfall Days', type: 'spline', color: '#CC9900', data: [10, 14, 18, 18, 24, 26, 25, 27, 24, 11, 10, 10]} ]"


class Graph:
    def __init__(self) -> None:
        super().__init__()

    def title(self):
        return "Monthly Average Snowfall"

    def json_parse(self, series: str):
        series = series.replace("'", '"')
        series = series.replace("tooltip", '"tooltip"')
        series = series.replace("valueSuffix", '"valueSuffix"')
        series = series.replace("name", '"name"')
        series = series.replace("color", '"color"')
        series = series.replace("type", '"type"')
        series = series.replace("data", '"data"')
        series = series.replace("yAxis", '"yAxis"')
        return json.loads(series)

    def parse_temp(self, data):
        precipitation = data[0]['data']
        average_rainfall_days = data[1]['data']
        frame = pd.DataFrame({"Snowfall (cm)": precipitation, "Average Snowfall Days": average_rainfall_days})
        frame.index = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
                       'November', 'December']
        return frame

    def parse(self, serise: str):
        parse = self.json_parse(serise)
        temp = self.parse_temp(parse)
        return temp


if __name__ == '__main__':
    graph = Graph()
    parse = graph.parse(mock_json)

    print(parse)
